home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / Snippets / Toolbox / PBAllocate / Alloc.c next >
Encoding:
C/C++ Source or Header  |  1995-02-11  |  2.0 KB  |  80 lines  |  [TEXT/MPS ]

  1. #include    <Files.h>
  2. #include    <Quickdraw.h>
  3. #include    <Windows.h>
  4. #include    <dialogs.h>
  5. #include    <OSEvents.h>
  6. #include    <StandardFile.h>
  7. #include    <Memory.h>
  8. #include    <StdIO.h>
  9.  
  10. #define    TRUE            0xFF
  11. #define    FALSE            0
  12.  
  13. main()
  14. {
  15.     ParmBlkPtr            myRecPtr;
  16.     HParmBlkPtr            myVRecPtr;
  17.     OSErr                err;
  18.     Point                where = {20,20};
  19.     SFReply                reply;
  20.     short                refnum;
  21.     char*                string;
  22.     
  23.     InitGraf(&qd.thePort);
  24.     FlushEvents(everyEvent, 0);
  25.     InitWindows();
  26.     InitDialogs(nil);
  27.     InitCursor();
  28.     
  29. /* does not work version */
  30.     
  31.     string = (char*) "\pWhere is junk file";
  32.  
  33.     SFGetFile (where, (Str255) string, nil, -1, (SFTypeList) nil, nil, &reply);
  34.     err = FSOpen(reply.fName, reply.vRefNum, &refnum);
  35.     if (err != noErr)
  36.         Debugger();
  37.         
  38.     myRecPtr = (ParmBlkPtr) NewPtrClear(sizeof(ParamBlockRec));;
  39.     myRecPtr->ioParam.ioRefNum = refnum;
  40.     myRecPtr->ioParam.ioReqCount = 0x7fffffff;
  41.  
  42.     err = PBAllocate (myRecPtr, FALSE);
  43.     
  44.     printf("error = %d, Actual count = %d\n",err, myRecPtr->ioParam.ioActCount);
  45.     
  46.     err = FSClose(refnum);
  47.     if (err != noErr)
  48.         Debugger();
  49.         
  50. /* The method which works - work around to above bug */
  51.  
  52.     string = (char*) "\pWhere is File";
  53.  
  54.     SFGetFile (where, (Str255) string, nil, -1, (SFTypeList) nil, nil, &reply);
  55.     err = FSOpen(reply.fName, reply.vRefNum, &refnum);
  56.     if (err != noErr)
  57.         Debugger();
  58.         
  59.     myVRecPtr = (HParmBlkPtr) NewPtrClear(sizeof(HParamBlockRec));;
  60.     myVRecPtr->volumeParam.ioVRefNum = reply.vRefNum;
  61.  
  62.     err = PBHGetVInfo(myVRecPtr, FALSE);
  63.     if (err != noErr)
  64.         Debugger();
  65.     
  66.     printf("# of blocks = %d\n Size of blocks = %d\n",myVRecPtr->volumeParam.ioVNmAlBlks, myVRecPtr->volumeParam.ioVAlBlkSiz);
  67.  
  68.     myRecPtr = (ParmBlkPtr) NewPtrClear(sizeof(ParamBlockRec));;
  69.     myRecPtr->ioParam.ioRefNum = refnum;
  70.     myRecPtr->ioParam.ioReqCount = (myVRecPtr->volumeParam.ioVNmAlBlks) * 
  71.                                     (myVRecPtr->volumeParam.ioVAlBlkSiz);
  72.  
  73.     err = PBAllocate (myRecPtr, FALSE);
  74.     
  75.     printf("error = %d, Actual count = %d\n",err, myRecPtr->ioParam.ioActCount);
  76.     
  77.     err = FSClose(refnum);
  78.     if (err != noErr)
  79.         Debugger();
  80. }